package admin

import (
	"github.com/gin-gonic/gin"
	"mydemo/models"
	"net/http"
)

type NavController struct {
	BaseController
}

func (con NavController) Index(c *gin.Context) {

	//	查询全部数据
	//navList := []models.Nav{}
	//models.DB.Find(&navList)
	//c.JSON(http.StatusOK, gin.H{"result": navList})

	//查询一条数据
	//nav := models.Nav{Id: 5}
	//models.DB.Find(&nav)
	//c.JSON(http.StatusOK, gin.H{"result": nav})

	//where 条件查询
	navList := []models.Nav{}
	models.DB.Where("id > 3").Find(&navList)
	models.DB.Where("id > ?", 3).Find(&navList)

	c.JSON(http.StatusOK, gin.H{"result": navList})
	//con.success(c)
}
func (con NavController) Add(c *gin.Context) {
	titles := []string{"商会组织", "赣商人文", "商会动态", "会员企业", "商会服务", "青海风情", "商会简介", "联系我们"}
	var navs []models.Nav
	for i, title := range titles {
		tem := models.Nav{
			Title:  title,
			Sort:   i + 1,
			Status: 1,
		}
		if err := models.DB.Create(&tem).Error; err != nil {
			c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
			return
		}
		navs = append(navs, tem)
	}
	c.JSON(http.StatusOK, navs)
}
func (con NavController) Edit(c *gin.Context) {

	con.success(c)
}
